package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.Role;
import com.realtyManage.springboot.Model.Do.Viki;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 购房百科
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-11-27
 */

@Repository
public interface VikiRepository extends JpaRepository<Viki, Long> {

    @Modifying
    @Transactional
    @Query("update Viki a set " +
            "a.title =  CASE WHEN :#{#viki.title} IS NULL THEN a.title ELSE :#{#viki.title} END, " +
            "a.content =  CASE WHEN :#{#viki.content} IS NULL THEN a.content ELSE :#{#viki.content} END, " +
            "a.isShow =  CASE WHEN :#{#viki.isShow} IS NULL THEN a.isShow ELSE :#{#viki.isShow} END " +
            "where a.id = :#{#viki.id}")
    int update(@Param("viki") Viki viki);


    @Query(value = "select * from viki where is_show = 1",nativeQuery = true)
    List<Viki> queryVikiList();

    @Query(value = "select * from viki where is_show = 1 and title like %?1%",nativeQuery = true)
    List<Viki> queryVikiListE(String title);

    @Query(value = "select * from viki where id = ?1",nativeQuery = true)
    Viki queryVikiById(Integer id);

}
